/*
 * Filename    : State_Game_Win.java
 * Projectname : RamaShinta
 * Date        : Nov 25, 2012 , 10:41:15 AM 
 * 
 */

package com.amikomgamedev.ramashinta.state;

import org.andengine.entity.modifier.ScaleAtModifier;
import org.andengine.entity.scene.ITouchArea;
import org.andengine.input.touch.TouchEvent;

import com.amikomgamedev.ramashinta.ServerData;
import com.amikomgamedev.ramashinta.Utils;

import android.view.KeyEvent;

public class State_Game_Win extends State_Game_Play
{
	private boolean isAttached = false;

	protected void create_State_Game_Win()
	{
		if(ServerData.getSelectedLevel()==ServerData.LEVEL10){
			graphic.attachStateLastWin();
			text.attachYouWin();
			
			if(isAttached){
				graphic.detachButtonTryWin();	
				graphic.detachNext();
			}
//			
		}else{
//			
			isAttached=true;
		graphic.attachStateWin();
		text.attachYouWin();
		}

	}
	
	@Override
	public boolean onAreaTouched(TouchEvent pSceneTouchEvent, ITouchArea pTouchArea, float pTouchAreaLocalX,
			float pTouchAreaLocalY)
	{
		if (State_Menu_Current == STATE_GAME_WIN)
		{
			if (pTouchArea.equals(graphic.spr_Btn_Next_Win))
			{
				Utils.TRACE("kliknext");
				for(int i=0;i<ServerData.LEVEL11;i++){
				if(ServerData.getSelectedLevel()==i){
					detachWinState();
				ServerData.setSelectedLevel(i+1);
				ServerData.setLevelSelection(ServerData.LEVEL_HUTAN);
				
				switchState(STATE_GAME_PLAY);
				break;
				
				
				}
				}
				// graphic.detachMenuLevel();
			} else if (pTouchArea.equals(graphic.spr_Btn_Try_Win))
			{
				for(int i=0;i<ServerData.LEVEL11;i++){
				if(ServerData.getSelectedLevel()==i){
					detachWinState();
					ServerData.setSelectedLevel(i);
					ServerData.setLevelSelection(ServerData.LEVEL_HUTAN);
					
					switchState(STATE_GAME_PLAY);
					
					
				}
				}
			}
		
		}

		return super.onAreaTouched(pSceneTouchEvent, pTouchArea, pTouchAreaLocalX, pTouchAreaLocalY);
	}
	
	private void detachWinState()
	{
		mEngine.runOnUpdateThread(new Runnable()
		{

			@Override
			public void run()
			{
				// TODO Auto-generated method stub
				if(ServerData.getSelectedLevel()==ServerData.LEVEL10){
				graphic.detachStateLastWin();
				text.detachYouWin();
				}
				else{
				graphic.detachStateWin();
				text.detachYouWin();
				}
			}
		});
	}


}
